﻿//https://leetcode.cn/problems/minimum-number-of-flips-to-make-binary-grid-palindromic-i/

class Solution {
public:
    int minFlips(vector<vector<int>>& grid)
    {
        int m = grid.size(), n = grid[0].size();
        int rowcount = 0, colcount = 0;

        //将所有行转换成回文串的次数
        for (int i = 0; i < m; i++)
        {
            int left = 0, right = n - 1;
            while (left <= right)
            {
                if (grid[i][left] != grid[i][right])
                {
                    rowcount++;
                }
                left++;
                right--;
            }

        }

        //将所有列转化成回文串的次数
        for (int i = 0; i < n; i++)
        {
            int left = 0, right = m - 1;
            while (left <= right)
            {
                if (grid[left][i] != grid[right][i])
                {
                    colcount++;
                }
                left++;
                right--;
            }

        }

        return min(rowcount, colcount);

    }
};
